/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package com.pancho;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class QuestFormDAO {
	public static QuestForm loadQuestFormByORMID(int idQuestForm) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadQuestFormByORMID(session, idQuestForm);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm getQuestFormByORMID(int idQuestForm) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return getQuestFormByORMID(session, idQuestForm);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByORMID(int idQuestForm, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadQuestFormByORMID(session, idQuestForm, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm getQuestFormByORMID(int idQuestForm, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return getQuestFormByORMID(session, idQuestForm, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByORMID(PersistentSession session, int idQuestForm) throws PersistentException {
		try {
			return (QuestForm) session.load(com.pancho.QuestForm.class, new Integer(idQuestForm));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm getQuestFormByORMID(PersistentSession session, int idQuestForm) throws PersistentException {
		try {
			return (QuestForm) session.get(com.pancho.QuestForm.class, new Integer(idQuestForm));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByORMID(PersistentSession session, int idQuestForm, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (QuestForm) session.load(com.pancho.QuestForm.class, new Integer(idQuestForm), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm getQuestFormByORMID(PersistentSession session, int idQuestForm, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (QuestForm) session.get(com.pancho.QuestForm.class, new Integer(idQuestForm), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm[] listQuestFormByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return listQuestFormByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm[] listQuestFormByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return listQuestFormByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm[] listQuestFormByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.QuestForm as QuestForm");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (QuestForm[]) list.toArray(new QuestForm[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm[] listQuestFormByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.QuestForm as QuestForm");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (QuestForm[]) list.toArray(new QuestForm[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadQuestFormByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return loadQuestFormByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		QuestForm[] questForms = listQuestFormByQuery(session, condition, orderBy);
		if (questForms != null && questForms.length > 0)
			return questForms[0];
		else
			return null;
	}
	
	public static QuestForm loadQuestFormByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		QuestForm[] questForms = listQuestFormByQuery(session, condition, orderBy, lockMode);
		if (questForms != null && questForms.length > 0)
			return questForms[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateQuestFormByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return iterateQuestFormByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateQuestFormByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.pancho.Taller1PDSPersistentManager.instance().getSession();
			return iterateQuestFormByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateQuestFormByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.QuestForm as QuestForm");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateQuestFormByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.pancho.QuestForm as QuestForm");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm createQuestForm() {
		return new com.pancho.QuestForm();
	}
	
	public static boolean save(com.pancho.QuestForm questForm) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().saveObject(questForm);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(com.pancho.QuestForm questForm) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().deleteObject(questForm);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(com.pancho.QuestForm questForm)throws PersistentException {
		try {
			if(questForm.getBabyMonitorCodSystem() != null) {
				questForm.getBabyMonitorCodSystem().setQuestForm(null);
			}
			
			if(questForm.getQuestionidQuest() != null) {
				questForm.getQuestionidQuest().setQuestForm(null);
			}
			
			return delete(questForm);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(com.pancho.QuestForm questForm, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(questForm.getBabyMonitorCodSystem() != null) {
				questForm.getBabyMonitorCodSystem().setQuestForm(null);
			}
			
			if(questForm.getQuestionidQuest() != null) {
				questForm.getQuestionidQuest().setQuestForm(null);
			}
			
			try {
				session.delete(questForm);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(com.pancho.QuestForm questForm) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().getSession().refresh(questForm);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(com.pancho.QuestForm questForm) throws PersistentException {
		try {
			com.pancho.Taller1PDSPersistentManager.instance().getSession().evict(questForm);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static QuestForm loadQuestFormByCriteria(QuestFormCriteria questFormCriteria) {
		QuestForm[] questForms = listQuestFormByCriteria(questFormCriteria);
		if(questForms == null || questForms.length == 0) {
			return null;
		}
		return questForms[0];
	}
	
	public static QuestForm[] listQuestFormByCriteria(QuestFormCriteria questFormCriteria) {
		return questFormCriteria.listQuestForm();
	}
}
